import com.beans.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

import java.security.cert.X509Certificate;

/**
 * Created with IntelliJ IDEA.
 * Description: Spring项目配置
 */
public class App {
    public static void main(String[] args) {
        // 1. 得到 spring 上下文对象
        ApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");
        // 2. 根据上下文对象提供的方法获取到 bean
        //User user = (User) context.getBean("userInfo");
        User user = context.getBean(User.class);
        // 3. 使用
        user.sayHi("张三");

//        // 1. 得到 bean 工厂
//        BeanFactory factory =
//                new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
//        // 2. 获取 bean
//        User user = (User) factory.getBean("userInfo");
//        // 3. 使用 bean
//        user.sayHi("lisi");
    }
}
